package com.miracle.mango.controller;

import com.miracle.mango.entity.permission.Permission;
import com.miracle.mango.entity.permission.PermissionMapper;
import com.miracle.mango.entity.permission.PermissionServive;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: wangxf
 * @date: Created in 2020/8/23 12:27
 */
@Api(tags = "权限管理")
@RestController
public class PermissionController {

    @Autowired
    private PermissionMapper permissionMapper;

    @Autowired
    private PermissionServive permissionService;

    @ApiOperation(value = "获取权限详情")
    @GetMapping("/permission/{id}")
    public Permission getById(@PathVariable("id") String id) {
        return permissionMapper.getById(id);
    }

    @ApiOperation(value = "保存权限")
    @PostMapping("/permission")
    public int save(Permission permission) {
        permission = new Permission();
        permission.setName("添加一个权限").setAction("/permission");
        return permissionService.save(permission);
    }

    @ApiOperation(value = "更新权限")
    @PutMapping("/permission")
    public int update(Permission permission) {
        permission = new Permission();
        permission.setName("更新一个权限").setAction("/permission");
        return permissionService.update(permission);
    }

    @ApiOperation(value = "删除权限")
    @DeleteMapping("/permission/{id}")
    public int remove(@PathVariable("id") String id) {
        return permissionService.removeById(id);
    }

}
